package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysArtistApplyMapper;
import com.ruoyi.system.domain.SysArtistApply;
import com.ruoyi.system.service.ISysArtistApplyService;

/**
 * 申请管理Service业务层处理
 * 
 * @author Yaphets
 * @date 2024-07-04
 */
@Service
public class SysArtistApplyServiceImpl implements ISysArtistApplyService 
{
    @Autowired
    private SysArtistApplyMapper sysArtistApplyMapper;

    /**
     * 查询申请管理
     * 
     * @param id 申请管理主键
     * @return 申请管理
     */
    @Override
    public SysArtistApply selectSysArtistApplyById(Long id)
    {
        return sysArtistApplyMapper.selectSysArtistApplyById(id);
    }

    /**
     * 查询申请管理列表
     * 
     * @param sysArtistApply 申请管理
     * @return 申请管理
     */
    @Override
    public List<SysArtistApply> selectSysArtistApplyList(SysArtistApply sysArtistApply)
    {
        return sysArtistApplyMapper.selectSysArtistApplyList(sysArtistApply);
    }

    /**
     * 新增申请管理
     * 
     * @param sysArtistApply 申请管理
     * @return 结果
     */
    @Override
    public int insertSysArtistApply(SysArtistApply sysArtistApply)
    {
        return sysArtistApplyMapper.insertSysArtistApply(sysArtistApply);
    }

    /**
     * 修改申请管理
     * 
     * @param sysArtistApply 申请管理
     * @return 结果
     */
    @Override
    public int updateSysArtistApply(SysArtistApply sysArtistApply)
    {
        return sysArtistApplyMapper.updateSysArtistApply(sysArtistApply);
    }

    /**
     * 批量删除申请管理
     * 
     * @param ids 需要删除的申请管理主键
     * @return 结果
     */
    @Override
    public int deleteSysArtistApplyByIds(Long[] ids)
    {
        return sysArtistApplyMapper.deleteSysArtistApplyByIds(ids);
    }

    /**
     * 删除申请管理信息
     * 
     * @param id 申请管理主键
     * @return 结果
     */
    @Override
    public int deleteSysArtistApplyById(Long id)
    {
        return sysArtistApplyMapper.deleteSysArtistApplyById(id);
    }

    /**
     *  校验是否有权限
     * @param sysArtistApply
     * @return
     */
    @Override
    public boolean checkRight(SysArtistApply sysArtistApply) {
        if(SecurityUtils.hasRole("@systemAdmin")){
            return true;
        }
        List<SysArtistApply> res = sysArtistApplyMapper.selectSysArtistApplyList(sysArtistApply);
        if(res.isEmpty()){
           return false;
        }else {
            List<Integer> vars =  res.stream().map(SysArtistApply::getApplyStatus).collect(Collectors.toList());
//            SysArtistApply obj = res.get(0);
            return  vars.contains(1);
        }
    }
}
